<?php


namespace App\Transformer;


use App\Models\TeamGoals;
use League\Fractal\TransformerAbstract;

class TeamGoalsTransformer extends TransformerAbstract
{

    protected $defaultIncludes = ['user'];

    public function transform(TeamGoals $data)
    {
        return [
            'id' => $data->id,
            'user_id' => $data->user_id,
            'amount' => $data->amount,
            'effect_mobile' => $data->effect_mobile,
            'intention' => $data->intention,
            'visit' => $data->visit,
            'order' => $data->order,
            'wechat' => $data->wechat,
            'month' =>  $data->month->format("Y-m"),
            'created_at' => $data->created_at->toDateTimeString()
        ];
    }

    public function includeUser(TeamGoals $data)
    {
        if ($data->relationLoaded('user') && $data->user) {
            return $this->item($data->user, new UserTransformer());
        }
    }

}
